<template>
  <div class="container">
    <div class="app-container">
      <el-tree
        :data="depts"
        :props="props"
        :expand-on-click-node="false"
        icon-class="el-icon-office-building"
        default-expand-all
        highlight-current
      >
        <template #default="{ data }">
          <el-row style="width: 100%" type="flex" justify="between" align="middle">
            <el-col>{{ data.name }}</el-col>
            <el-col align="center">{{ data.type }}</el-col>
            <el-col align="center">{{ data.managerName }}</el-col>
            <el-col align="center">{{ data.member || 0 }}人</el-col>
            <el-col align="center">
              <el-button type="text">编辑</el-button>
              <el-button type="text" style="margin: 0 10px">删除</el-button>
              <el-button type="text">新增子项</el-button>
            </el-col>
          </el-row>
        </template>
      </el-tree>
    </div>
  </div>
</template>

<script>
import { getDepartmentList } from '@/api/homework/zuzhijiagou'
import { transListToTreeData2 } from '@/utils'
export default {
  data() {
    return {
      // 组织架构列表数据
      depts: [],
      // 读取数据的字段名
      props: { label: 'name', children: 'children' }
    }
  },
  created() {
    // 获取组织架构列表数据
    this.getDepartments()
  },
  methods: {
    // 获取组织架构列表数据
    async getDepartments() {
      // 调用组织架构列表接口
      const res = await getDepartmentList()
      console.log(res.data)
      this.depts = transListToTreeData2(res.data, 0)
    }
  }
}
</script>
